package com.lyl.momanapp.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lyl.momanapp.R;
import com.lyl.momanapp.util.utlis.DataCleanManager;
import com.lyl.momanapp.util.view.MyBaseActivity;

/**
 * Created by lyl on 2017/11/15.
 */

public class SetActivity extends MyBaseActivity {

    String TAG = "SetActivity";

    private TextView mQingliNum;
    private LinearLayout mqingli;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.help_qingli: {
                DataCleanManager.cleanApplicationData(SetActivity.this);
                info();
                Log.i("1111111111111", "onClick: ");
            }
            break;
            case R.id.fanhui: {
                finish();
            }
            break;
            case R.id.zhuye: {

                startActivity(new Intent(SetActivity.this, MainActivity.class));
                finish();
            }
        }
    }

    @Override
    public void initUI() {
        setContentView(R.layout.activity_set);
        mQingliNum = ((TextView) findViewById(R.id.help_qingli_num));
        mqingli = ((LinearLayout) findViewById(R.id.help_qingli));
        findViewById(R.id.fanhui).setOnClickListener(this);
        findViewById(R.id.zhuye).setOnClickListener(this);
    }

    @Override
    public void initData() {
        info();
    }

    private void info() {
        try {
            long folderSize = DataCleanManager.getFolderSize(SetActivity.this.getFilesDir());
            long folderSize2 = DataCleanManager.getFolderSize(SetActivity.this.getCacheDir());

            Log.e(TAG, "folderSize  " + folderSize);
            Log.e(TAG, "folderSize2  " + folderSize2);

            if (folderSize != 0) {
                String formatSize = DataCleanManager.getFormatSize(folderSize);
                mQingliNum.setText(formatSize);
            } else {
                mQingliNum.setText("0.00 MB");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void addListeners() {
        mqingli.setOnClickListener(this);
    }
}
